package com.nineclock.auth.intergration.exception;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;

public class NcOAuthExceptionJacksonSerializer  extends StdSerializer<NcOAuth2Exception> {

    public NcOAuthExceptionJacksonSerializer(){
        super(NcOAuth2Exception.class);
    }

    /**
     * {
     *     "success":false,
     *     "code":"",
     *     "message":"..."
     * }
     * @param e
     * @param jsonGenerator
     * @param serializerProvider
     * @throws IOException
     */
    @Override
    public void serialize(NcOAuth2Exception e, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        jsonGenerator.writeStartObject();

        jsonGenerator.writeObjectField("success", false);
        jsonGenerator.writeObjectField("code", e.getHttpErrorCode());
        jsonGenerator.writeObjectField("message", e.getMessage());

        jsonGenerator.writeEndObject();
    }

}
